package com.jn.erp.web.api.interaction.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.jn.erp.common.core.result.AjaxResult;
import com.jn.erp.security.controller.BaseWebAuthController;
import com.jn.erp.web.api.interaction.entity.TIntegralConfig;
import com.jn.erp.web.api.interaction.entity.vo.TEvaluateVo;
import com.jn.erp.web.api.interaction.service.TIntegralConfigService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RestController;

import java.time.LocalDateTime;
import java.util.Map;
import java.util.Objects;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author wyp
 * @since 2024-10-10
 */
@RestController
@RequestMapping("/tIntegralConfig")
public class TIntegralConfigController  extends BaseWebAuthController {
    @Autowired
    private TIntegralConfigService tIntegralConfigService;

    /**
     保存修改
     */
    @PostMapping("saveAndUpdate")
    public AjaxResult saveAndUpdate(@RequestBody TIntegralConfig tIntegralConfig){
        //机构id
        tIntegralConfig.setOrgId(Long.parseLong(loginDeptAuth()) );

        if(Objects.isNull(tIntegralConfig.getId())){
            //当前登录人id
            tIntegralConfig.setCreateUser(String.valueOf(getUserId()) );
            tIntegralConfig.setCreateDate(LocalDateTime.now() );
            tIntegralConfig.setIsDelete("0");
            tIntegralConfigService.save(tIntegralConfig);
        }else {
            //当前登录人id
            tIntegralConfig.setUpdateUser(String.valueOf(getUserId()) );
            tIntegralConfig.setUpdateDate(LocalDateTime.now() );
            tIntegralConfigService.updateById(tIntegralConfig);
        }
        return AjaxResult.success("S00");
    }
    /**
     获取
     */
    @PostMapping("getOne")
    public AjaxResult getOne(@RequestBody TIntegralConfig tIntegralConfig){
        //机构id
        tIntegralConfig.setOrgId(Long.parseLong(loginDeptAuth()) );

        TIntegralConfig t = tIntegralConfigService.getOne(new QueryWrapper<TIntegralConfig>().eq("org_id", loginDeptAuth()).eq("is_delete","0"));
        return AjaxResult.success(t);
    }
}

